package com.lin.security;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.lin.entity.User;
import com.lin.mapper.UserMapper;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author linze
 * @version 1.0
 * @Description
 * @Date 2021/1/21 18:03
 */
@Service
public class SecurityUserService  implements UserDetailsService {

    @Resource
    UserMapper userMapper;
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {

        User user = userMapper.selectOne(new QueryWrapper<User>().eq(User.USERNAME,s));
        if(user==null){
            throw new UsernameNotFoundException(s+"not find");
        }
        return new SecurityUser(user);
    }

}
